package com.zhiyou100.api.object_demo;

import java.util.Objects;

//所有的类都是Object的子类
public class Student {

    private String name;
    private int age;
    private String num;

    public Student() {
    }

    public Student(String name, int age, String num) {
        this.name = name;
        this.age = age;
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    //重写父类Object的toString方法
    @Override
    public String toString() {
        return "Student{name= " + name + ",age = " + age + ",num = " + num + "}";
    }

    //重写Object提供的equals方法
    @Override
    public boolean equals(Object obj) {
        //判断被比较对象是否属于当前类型
        if (obj instanceof Student) {
            Student stu = (Student) obj;
            if (Objects.equals(name,stu.name)
                    && this.age == stu.age
                    && Objects.equals(num,stu.num)) {
                return true;
            }else {
                return false;
            }
        } else {
            return false;
        }
    }


}
